<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<script th:inline="javascript">
	var userField = '[(${userField})]';

	if (userField != '') {
		function initOnUserFieldChange[(${field})]() {
			var oldValue_[(${userField})] = ""; // 一个不存在的值
			var sint = setInterval(function(){
				if (findObj("[(${userField})]")) {
					if (oldValue_[(${userField})] != findObj("[(${userField})]").value) {
						oldValue_[(${userField})] = findObj("[(${userField})]").value;
						onUserChange_[(${field})]();
					}
				} else {
					// console.log('initOnUserFieldChange clearInterval');
					// 不能清除，因为当表单域选择控件在打开查询抽屉时，主表上的findObj(userField)就找不到了，当关闭抽屉再回到主表时，仍需检查关联的用户型字段是否有变化
					// window.clearInterval(sint);
				}
			},500);

			getCurFormUtil().addInterval(sint, "[(${formName})]");
		}
		initOnUserFieldChange[(${field})]();

		function onUserChange_[(${field})]() {
			var ajaxData = {
				formCode: "[(${formCode})]",
				userName: $(fo('[(${userField})]')).val(),
				field: "[(${field})]",
				roleCodes: '[(${roles})]',
			}
			ajaxPost('/flow/macro/getRoleUserRelatedToUser', ajaxData).then((res) => {
				console.log('getRoleUserRelatedToUser', res);
				if (res.code === 200) {
					if (res.data.res === 0) {
						$(fo("[(${field})]")).val(res.data.userName);
						$(fo("[(${field})]_realshow")).val(res.data.realName);
					}
				}
			});
		}
	}
</script>
</body>
</html>